function pvalue = tstat2pval(tstat)

N = length(tstat);
ind = (tstat<=0);
pvalue = NaN(N,1);
pvalue(~~ind) = 2*normcdf(tstat(~~ind),0,1);
pvalue(~ind) = 2*(1-normcdf(tstat(~ind),0,1));

return